#ifndef _vlc_player_h_
#define _vlc_player_h_

#include <vector>
#include "vlc/vlc.h"
#include "audio_render.h"
#include "video_render.h"

class VlcPlayer {
public:
    VlcPlayer(std::string mediaURL, std::string id, int32_t width = 0, int32_t height = 0, \
                std::vector<std::string> args = std::vector<std::string>());
    ~VlcPlayer();
    int32_t Init();
    int32_t Play();
    int32_t Pause();
    int32_t Stop();
    class RenderCallbacks {
        public:
        static void *VideoLock(void *videoRender, void **planes);
        static void VideoDisplay(void *videoRender, void *picture);
        static void VideoUnlock(void *videoRender, void *picture, void *const *planes);
        static unsigned VideoFormatCB(void **videoRender, char *frameFormat, unsigned *width, unsigned *height,unsigned *pitches, unsigned *lines);
        static void AudioPlay(void *audioRender, const void *samples, unsigned count, int64_t pts);
        static void AudioPause(void *audioRender, int64_t pts);
        static void AudioResume(void *audioRender, int64_t pts);
        static void AudioFlush(void *audioRender, int64_t pts);
        static void AudioDrain(void *audioRender);
        static int AudioSetupCB(void **data, char *format, unsigned *rate, unsigned *channels);
    };
    libvlc_state_t State() const;
private:
    std::string id_;
    std::string mediaURL_;
    std::vector<std::string> args_;
    libvlc_instance_t *instance_ {nullptr};
    libvlc_media_player_t *player_ {nullptr};
    libvlc_state_t state_ {libvlc_NothingSpecial};
    int32_t width_ {0};
    int32_t height_ {0};
    int32_t channels_ {2};
    std::unique_ptr<VideoRender> videoRenderUptr_ {nullptr};
    std::unique_ptr<AudioRender> audioRenderUptr_ {nullptr};
};

#endif